package com.zheng.flink.study.dataset.transformation;

import org.apache.flink.api.common.functions.FilterFunction;
import org.apache.flink.api.common.functions.FlatMapFunction;
import org.apache.flink.api.java.ExecutionEnvironment;
import org.apache.flink.util.Collector;

import java.util.Arrays;

/**
 * @author zhengbo
 * @date 2019/12/12
 */
public class FilterTransformation {

    public static void main(String[] args) throws Exception {

        ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

        env.fromCollection(Arrays.asList(1, 2, 5, 6, 99, 66, 999, 666)).flatMap(
                new FlatMapFunction<Integer, Integer>() {
                    @Override
                    public void flatMap(Integer value, Collector<Integer> out) throws Exception {

                        out.collect(value * 2);
                    }
                })
                .filter(new FilterFunction<Integer>() {
                    @Override
                    public boolean filter(Integer value) throws Exception {
                        return value > 100;
                    }
                });

//        env.fromCollection(Arrays.asList(1, 2, 5, 6, 99, 66, 999, 666))
//                .filter(new FilterFunction<Integer>() {
//                    @Override
//                    public boolean filter(Integer value) throws Exception {
//                        return value != null && value > 100;
//                    }
//                }).print();
    }
}
